package org.martyn.danbodroid.gui;

import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ProgressBar;

import org.martyn.danbodroid.R;

public class ActionBar
{
	Activity activity;

	public ActionBar(Activity activity)
	{
		this.activity = activity;
	}

	public void setTitle(CharSequence title)
	{
		((Button) activity.findViewById(R.id.titleButton)).setText(title);
	}

	
	public void setHomeButtonOnClickListener(OnClickListener onClickListener)
	{
		activity.findViewById(R.id.homeButton).setOnClickListener(onClickListener);
	}
	
	public void setSearchButtonOnClickListener(OnClickListener onClickListener)
	{
		activity.findViewById(R.id.searchButton).setOnClickListener(onClickListener);
	}
	
	public void setShareButtonOnClickListener(OnClickListener onClickListener)
	{
		activity.findViewById(R.id.shareButton).setOnClickListener(onClickListener);
	}
	
	public void setRefreshButtonOnClickListener(OnClickListener onClickListener)
	{
		activity.findViewById(R.id.refreshButton).setOnClickListener(onClickListener);
	}
	
	public void setHomeButtonVisable(boolean visable)
	{
		((ImageButton) activity.findViewById(R.id.homeButton))
		.setVisibility(visable ? View.VISIBLE : View.GONE);

		((ImageView) activity.findViewById(R.id.homeButtonSeperator))
		.setVisibility(visable ? View.VISIBLE : View.GONE);
	}

	public void setShareButtonVisable(boolean visable)
	{
		//TODO: Verkorten
		if (visable)
		{
			((ImageButton) activity.findViewById(R.id.shareButton))
					.setVisibility(View.VISIBLE);
			((ImageView) activity.findViewById(R.id.shareButtonSeperator))
					.setVisibility(View.VISIBLE);
		}
		else
		{
			((ImageButton) activity.findViewById(R.id.shareButton))
					.setVisibility(View.GONE);
			((ImageView) activity.findViewById(R.id.shareButtonSeperator))
					.setVisibility(View.GONE);
		}
	}

	public void setSearchButtonVisable(boolean visable)
	{
		//TODO: Verkorten
		if (visable)
		{
			((ImageButton) activity.findViewById(R.id.searchButton))
					.setVisibility(View.VISIBLE);
			((ImageView) activity.findViewById(R.id.searchButtonSeperator))
					.setVisibility(View.VISIBLE);
		}
		else
		{
			((ImageButton) activity.findViewById(R.id.searchButton))
					.setVisibility(View.GONE);
			((ImageView) activity.findViewById(R.id.searchButtonSeperator))
					.setVisibility(View.GONE);
		}
	}

	public void setRefreshButtonVisable(boolean visable)
	{
		//TODO: Verkorten
		if (visable)
		{
			((ImageButton) activity.findViewById(R.id.refreshButton))
					.setVisibility(View.VISIBLE);
			((ImageView) activity.findViewById(R.id.refreshButtonSeperator))
					.setVisibility(View.VISIBLE);
		}
		else
		{
			((ImageButton) activity.findViewById(R.id.refreshButton))
					.setVisibility(View.GONE);
			((ImageView) activity.findViewById(R.id.refreshButtonSeperator))
					.setVisibility(View.GONE);
		}
	}

//	public void setProgressBarVisable(boolean visable)
//	{
//		//TODO: Verkorten
//		if (visable)
//		{
//			((ImageButton) activity.findViewById(R.id.refreshBar))
//					.setVisibility(View.VISIBLE);
//			((ImageView) activity.findViewById(R.id.refreshBarSeperator))
//					.setVisibility(View.VISIBLE);
//		}
//		else
//		{
//			((ImageButton) activity.findViewById(R.id.refreshBar))
//					.setVisibility(View.GONE);
//			((ImageView) activity.findViewById(R.id.refreshBarSeperator))
//					.setVisibility(View.GONE);
//		}
//	}

	public void setRefreshButtonState(boolean refreshing)
	{	
		ImageButton refreshButton = ((ImageButton) activity.findViewById(R.id.refreshButton));
		refreshButton.setVisibility(refreshing ? View.GONE : View.VISIBLE);

		ImageView refreshButtonSeperator = ((ImageView) activity.findViewById(R.id.refreshButtonSeperator));
		refreshButtonSeperator.setVisibility(refreshing ? View.GONE : View.VISIBLE);
		
		ProgressBar refreshBar = ((ProgressBar) activity.findViewById(R.id.refreshBar));
		refreshBar.setVisibility(refreshing ? View.VISIBLE : View.GONE);

		ImageView refreshBarSeperator = ((ImageView) activity.findViewById(R.id.refreshBarSeperator));
		refreshBarSeperator.setVisibility(refreshing ? View.VISIBLE : View.GONE);

	}

}